<template>
	<view class="modular">
		<view class="headerBox">
			<view class="header">
				<view class="information">
					<view>
						<view><text>会员</text>：{{data.userName}} </view>
						<view><text>填写日期</text>：{{data.fillFormDate}}</view>
					</view>
					<view>
						<view><text>性别</text>：{{userInfo.sex && userInfo.sex == 1 ? '男' :userInfo.sex == 2 ? '女' :'' || ''}} </view>
						<view><text>年龄</text>：{{userInfo && userInfo.age}}</view>
					</view>
					<view>
						<view><text>评估人</text>：{{data.healthName}}</view>
						<view><text>评估日期</text>：{{data.modifiedDate ? data.modifiedDate : data.createdDate}}</view>
					</view>
				</view>
			</view>

			<view class="connectBox" v-show="!searchBarFixed">
				<image src="@/static/img/healthStatus/connect@2x.png"></image>
				<image src="@/static/img/healthStatus/connect@2x.png"></image>
			</view>
		</view>
		<view class="mainContent">
			<view class="specific">
				<image src="@/static/img/healthStatus/ask@2x.png" class="title"></image>
				<view v-for="(item,index) in questionnaire" :key="index">
					<view class="single" v-for="(aitem,aindex) in item.adTopicsRepliesEntityList" :key="aindex">
						<image src="@/static/img/healthStatus/questionIcon@2x.png"></image>
						<view>
							<view class="question">{{aitem.name}}</view>
							<view class="answer">{{aitem.setValue && aitem.setValue.substr(0,2) || '未选择'}}</view>
						</view>
					</view>
				</view>

			</view>

			<view class="specific">
				<image src="@/static/img/healthStatus/smell@2x.png" class="title"></image>
				<view class="single"  v-for="(sitem,sindex) in lookAndSmellDetails" :key="sindex">
					<image src="@/static/img/healthStatus/questionIcon@2x.png"></image>
					<view>
						<view class="question">{{sitem.name}}</view>
						<view class="answer">
							{{sitem.setValue || '未选择'}}
						</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		age,
		distance
	} from '@/static/js/filter.js'
	export default {
		data() {
			return {
				questionnaire: {},
				lookAndSmellDetails: {},
				data: {},
				answer: [],
				userInfo: {},
				searchBarFixed: false,
				id:'',
				sex:''
			}
		},
		onLoad(option) {
			this.sex = localStorage.getItem('userInfo') && JSON.parse(localStorage.getItem('userInfo')).sex;
			if (option.id) {
				this.id = option.id;
				this.question().then((reponse) => {
					this.lookAndSmellQuestion()
					if(reponse) {
						this.interface()
					}
					
				})
			}
		},
		onPageScroll() {
			this.searchBarFixed = this.distance('mainContent');
		},
		methods: {
			age,
			distance,
			interface() {
				const _this = this;
				_this.$api.psychologyQuestionInfo(this.id).then((res) => {
					if (res.data.returnCode == 200) {
						_this.data = res.data.result.newAppMentalHealthAssessmentEntity;
						const answer = res.data.result.newUserTopicsEntities;
						_this.questionnaire && _this.questionnaire.map((a) => { //问
							a && a.adTopicsRepliesEntityList.map((b) => {
								answer && answer.map((c) => {
									if (b.id == c.titleId) {
										b.adTopicsRepliesEntityList.map((d) => {
											if (d.elections == c.userOption) {
												b.setValue = d.value;
											}
										})
									}
								})
							})
						})
						_this.lookAndSmellDetails && _this.lookAndSmellDetails.map((a) => {
							a.adTopicsRepliesEntityList.map((b) => {
								answer && answer.map((c) => {
									if(a.id == c.titleId) {
										a.setValue = c.userValue
									}
								})
							})
						})
						_this.$api.getUserInfo().then((res) => {
							if (res.data.returnCode == 200) {
								_this.userInfo = res.data && res.data.result;
							}
						})
					}
				})
			},
			question() {
				return new Promise((success, error) => {
					this.$api.psychologyQuestion('ids=30&ids=31&ids=32&ids=33&ids=34&ids=35&ids=36&ids=37&ids=38').then((res) => {
						if (res) {
							const data = Object.keys(res.data.result).map((a) => {
								const aData = res.data.result[a].adTopicsRepliesEntityList.map((b) => {
									b.adTopicsRepliesEntityList.map((c) => {
										c.checked = false;
										return b
									})
									return b
								})
								return res.data.result[a]
							})
							this.sex == 2 ? data[5].adTopicsRepliesEntityList.splice(6, 1) : data[5].adTopicsRepliesEntityList.splice(5,
								1);
							this.questionnaire = data;
							success(res.data.result)
						} else {
							error('')
						}
					})
				})
			},
			// 望闻切题目
			lookAndSmellQuestion() {
				return new Promise((success, error) => {
					this.$api.psychologyQuestion('ids=39').then((res) => {
						if (res) {
							this.lookAndSmellDetails = res.data.result[39] && res.data.result[39].adTopicsRepliesEntityList.map((a) => {
								a.adTopicsRepliesEntityList.map((b) => {
									return b.checked = false
								})
								return a
							});
							success(res.data.result[39])
						} else {
							error('')
						}
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/css/healthStatus/toView.scss';
</style>
